package weiyao.xinxidasai.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import weiyao.xinxidasai.service.FileNotaryService;

@RestController
@RequestMapping("/nota")
public class NotaController {
     @Autowired
    private FileNotaryService fileNotaryService;



    // 文件加密上传接口
    @PostMapping("/encrypt")
    public ResponseEntity<Resource> encryptFile(
            @RequestParam("file") MultipartFile file) throws Exception {

        // 参数校验
        if (file.isEmpty()) {
            throw new IllegalArgumentException("上传文件不能为空");
        }

        return fileNotaryService.encryptFile(file);
    }

    // 文件认证解密接口
    @PostMapping("/verify")
    public Object verifyFile(
            @RequestParam("file") MultipartFile encryptedFile) throws Exception {

        // 参数校验
        if (encryptedFile.isEmpty()) {
            throw new IllegalArgumentException("上传文件不能为空");
        }

        return fileNotaryService.verifyFile(encryptedFile);
    }
}